package com.kingwood.algorithm.test200;

import java.util.Scanner;

/**
 * 员工派遣
 * https://blog.csdn.net/qfc_128220/article/details/135050312
 * @return
 */
public class YuanGongPaiQian {
    static int x;
    static int y;
    static long cntX;
    static long cntY;

    public static long getMinYuanGong() {
        long min = cntX + cntY;
        long max = 1000000000L;

        while (min <= max) {
            long mid = min + (max - min) / 2;
            if (checkYuanGong(mid)) {
                max = mid - 1;
            } else {
                min = mid + 1;
            }
        }

        return min;
    }

    public static boolean checkYuanGong(long k) {
        long a = k / x;
        long b = k / y;
        long c = k / (x * y);

        return Math.max(0, cntX - (b - c)) + Math.max(0, cntY - (a - c)) <= k - a - b + c;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        x = scanner.nextInt();
        y = scanner.nextInt();
        cntX = scanner.nextLong();
        cntY = scanner.nextLong();

        System.out.println(getMinYuanGong());
    }
}
